﻿using System.Collections.Generic;

using Ah.Testudin.Engine.Graphics;
using Ah.Testudin.Engine.UI.Views;

using Microsoft.Xna.Framework;

namespace Ah.Testudin.Engine.State
{
    public abstract class ApplicationStateBase : IApplicationState
    {
        #region Private Member Variables

        protected IList<IGameView> _gameViews;

        protected ITestudinRenderer _renderer;

        #endregion

        #region Constructors

        public ApplicationStateBase()
        {
            _gameViews = new List<IGameView>();

            _renderer = GraphicsDeviceRendererSingleton.Instance;
        }

        #endregion

        #region IApplicationState

        public abstract void Load();

        public virtual bool HandleInput()
        {
            foreach (IGameView currentGameView in _gameViews)
            {
                if (currentGameView.ProcessInput())
                {
                    return true;
                }
            }

            return false;
        }

        public abstract void Update(GameTime gameTime);

        public virtual void Render()
        {
            _renderer.PreRender();

            foreach (IGameView currentGameView in _gameViews)
            {
                currentGameView.Render();
            }

            _renderer.PostRender();
        }

        public abstract void RenderDiagnostics(GameTime gameTime);

        #endregion
    }
}
